package com.hxd.otc.module.order.model;

import android.support.annotation.NonNull;

import com.hxd.otc.api.IAdOrderApi;
import com.hxd.otc.api.IOrderApi;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.order.bean.AdOrderDetailBean;
import com.hxd.otc.module.order.bean.AllOrderBean;
import com.hxd.otc.module.order.bean.AppealBean;
import com.hxd.otc.module.order.bean.BankInfoPoData;
import com.hxd.otc.module.order.bean.RedPointBean;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.net.RetrofitManager;
import com.uber.autodispose.AutoDisposeConverter;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * 包  名 :  com.hxd.otc.mvp.order
 * 类  名 :  AllOrderModel
 * 作  者 :  zjl
 * 时  间 :  2018/6/6 15:05
 * 描  述 :  ${TODO}
 */
public class AllOrderModel {

    private static class SingletonHolder {
        private static final AllOrderModel instance = new AllOrderModel();
    }

    public static AllOrderModel getInstance() {
        return AllOrderModel.SingletonHolder.instance;
    }

    public void getOrderList(BaseObserver observer, AutoDisposeConverter<BaseBean<AllOrderBean>> converter, @NonNull int... category) {

        if (category[0] == -1) {
            RetrofitManager.getDefault()
                    .create(IOrderApi.class)
                    .getOrderList(category[1], category[2])
                    .observeOn(AndroidSchedulers.mainThread())
                    .as(converter)
                    .subscribe(observer);
        } else {
            RetrofitManager.getDefault()
                    .create(IOrderApi.class)
                    .getOrderList(category[0], category[1], category[2])
                    .observeOn(AndroidSchedulers.mainThread())
                    .as(converter)
                    .subscribe(observer);
        }


    }

    /**
     * 获取订单详情 的接口
     */
    public void getOrderDetailData(BaseObserver observer, AutoDisposeConverter<BaseBean<AllOrderBean.DataBean>> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .getOrderDetail(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);

    }

    /**
     * 卖出---未付款----取消订单操作
     */
    public void cancleDetal(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        if (category[1].equals("0")) {//全部
            RetrofitManager.getDefault()
                    .create(IOrderApi.class)
                    .cancleOrder(category[0])
                    .observeOn(AndroidSchedulers.mainThread())
                    .as(converter)
                    .subscribe(observer);
        } else {//部分确认收款
            RetrofitManager.getDefault()
                    .create(IOrderApi.class)
                    .cancleEasyPayOrder(category[0])
                    .observeOn(AndroidSchedulers.mainThread())
                    .as(converter)
                    .subscribe(observer);
        }

    }

    /**
     * 获取订单银行卡列表
     */
    public void getOrderBankList(BaseObserver<List<BankInfoPoData>> observer, AutoDisposeConverter<BaseBean<List<BankInfoPoData>>> converter,
                                 @NonNull String... category) {
        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .getOrderBankList(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 购买---未付款----我已付款操作
     */
    public void paidOrder(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        if (category[3].equals("0")) {//全部
            RetrofitManager.getDefault()
                    .create(IOrderApi.class)
                    .paidOrder(category[0], category[1], category[2])
                    .observeOn(AndroidSchedulers.mainThread())
                    .as(converter)
                    .subscribe(observer);

        } else {
            RetrofitManager.getDefault()
                    .create(IOrderApi.class)
                    .paidEasePayOrder(category[0], category[1], category[2])
                    .observeOn(AndroidSchedulers.mainThread())
                    .as(converter)
                    .subscribe(observer);
        }

    }

    /**
     * 购买（卖出）---申诉状态----申诉撤回 操作
     */
    public void recallOrder(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .recallOrder(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 卖出---已付款状态----确认收款 操作
     */
    public void receiveOrder(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {
        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .receiveOrder(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);

    }

    /**
     * 卖出---已付款状态----部分确认收款 操作
     */
    public void partConfirmOrder(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .partConfirmOrder(category[0], category[1])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    public void getAppealList(BaseObserver observer, AutoDisposeConverter<BaseBean<List<AppealBean>>> converter) {

        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .getAppealList()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);

    }

    public void cancleAppeal(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, String appealId) {

        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .cancleAppeal(appealId)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);

    }

    /**
     * 获取订单红点
     */
    public void redPointFlag(BaseObserver observer, AutoDisposeConverter<BaseBean<RedPointBean>> converter) {

        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .redPointFlag()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**====================带Ad  字样的是广告商订单相关的操作========================================================== */

    /**
     * 获取订单红点
     */
    public void redAdPointFlag(BaseObserver observer, AutoDisposeConverter<BaseBean<RedPointBean>> converter) {

        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .redPointFlag()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }


    public void getAdOrderList(BaseObserver observer,
                               AutoDisposeConverter<BaseBean<AllOrderBean>> converter, @NonNull int... category) {
        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .getOrderList(category[0], category[1], category[2])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);

    }

    /**
     * 获取订单详情 的接口
     */
    public void getAdOrderDetailData(BaseObserver observer, AutoDisposeConverter<BaseBean<AdOrderDetailBean>> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .getOrderDetail(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);

    }

    /**
     * 卖出---已付款状态----确认收款 操作
     */
    public void receiveAdOrder(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {
        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .receiveOrder(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * （卖出）---申诉状态----申诉撤回 操作
     */
    public void recallAdOrder(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .recallOrder(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 购买---未付款----我已付款操作
     */
    public void paidAdOrder(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .paidOrder(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 未付款----同意对方取消交易取消订单操作
     */
    public void confirmAdCancel(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .confirmCancel(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 未付款----拒绝取消交易取消订单操作
     */
    public void rejectAd(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .reject(category[0])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 未付款----上传固定二维码
     */
    public void fixQRcode(BaseObserver observer, AutoDisposeConverter<BaseBean> converter, @NonNull String... category) {

        RetrofitManager.getDefault()
                .create(IAdOrderApi.class)
                .fixQRcode(category[0], category[1], category[2])
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

}
